public class BinarySearch {
	public static void main(String[] args) {
		int arr[]={1,2,3,4,5,6,7,8,9,10};
		System.out.println(Search(arr,10));
	}
	
	public static int Search(int[] arr,int input) {
		int lower=0,upper=arr.length-1,middle=0;
		while(lower<=upper) {
			middle=(lower+upper)/2;
			if(input>arr[middle]) {
				lower=middle+1;
			}
			else if(input<arr[middle]) {
				upper=middle+1;
			}
			else {
				break;
			}
		}
		if(input==arr[middle]) {
			return middle+1;
		}
		else {
			return -1;
		}
	}
}